home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0097_Re: Detecting devices.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  971 b   |  31 lines

  1. {
  2.  BP> Is there some way I can use interrupts or whatever to detect whether
  3.  BP> the "file name" contained in the S string variable is a device name
  4.  BP> (such as "CON", "LPT1", "AUX", etc) or not?
  5.  
  6. Yes: use the ubiquitious INT $21. }
  7.  
  8. FUNCTION IsDevice(CONST Fname: PathStr): boolean;
  9. { -- Returns TRUE if named file is actually a device.
  10.   -- Example: IsDevice('CON') = TRUE, IsDevice(paramstr(0)) = FALSE.
  11.   -- N.B.: returns FALSE if FName is a non-existent file. }
  12. VAR Regs: Registers;
  13.     F   : FILE;
  14.     FH  : word ABSOLUTE F;
  15. BEGIN IsDevice := FALSE;
  16.       assign(F, Fname);
  17.       reset(F, 1);
  18.       IF IOresult <> 0 THEN exit;
  19.       WITH Regs
  20.       DO BEGIN { -- Get information about file: }
  21.                AX := $4400;
  22.                BX := FH;
  23.                MsDos(Regs);
  24.                IF NOT odd(Flags) AND (DL AND $80 <> 0)
  25.                THEN IsDevice := TRUE
  26.          END;
  27.       close(F);
  28.       IF IOresult <> 0 THEN ;
  29. END;
  30.  
  31.